import org.springframework.stereotype.Service;
import org.springframework.http.ResponseEntity;

import javax.servlet.http.HttpSession;

@Service
public class LoginServiceImp implements LoginService{

    @Override
    public ResponseEntity<Void> login(RoleDao roleDao, HttpSession session) {
        //数据库的数据
        RoleDao roleDao1 = new RoleDao(1,Role.ADMIN,"123","123");
        RoleDao roleDao2 = new RoleDao(2,Role.USER,"1234","1234");
        if(roleDao.getUsername().equals(roleDao1.getUsername()) && roleDao.getPassword().equals(roleDao1.getPassword())){
            roleDao.setRole(Role.ADMIN);
            roleDao.setId(roleDao1.getId());
        } else if (roleDao.getUsername().equals(roleDao2.getUsername()) && roleDao.getPassword().equals(roleDao2.getPassword())) {
            roleDao.setRole(Role.USER);
            roleDao.setId(roleDao2.getId());
        }else {
            roleDao.setRole(Role.GUEST);
        }
        session.setAttribute("user",roleDao);
        return ResponseEntity.ok().build();
    }
}
